import path from "path";
import vue from '@vitejs/plugin-vue';
import UnoCss from "unocss/vite";
// keepAlive 组件name
import vueSetupExtend from "vite-plugin-vue-setup-extend";
// gzip压缩
import viteCompression from "vite-plugin-compression";
// 引入svg需要的插件
import {createSvgIconsPlugin} from "vite-plugin-svg-icons";
import compression from "vite-plugin-compression";

import appInfo from './app-info.js';
import createDevtools from './devtools.js';
import createAutoImport from './auto-import.js';
import createComponents from './components.js';

export default function createVitePlugins(viteEnv, isBuild = false) {
  const vitePlugins = [
    appInfo(),
    vue(),
    UnoCss(),
    vueSetupExtend(),
    viteCompression(),
    createSvgIconsPlugin({
      // 配置SVG图片
      iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
      symbolId: "icon-[dir]-[name]"
    }),
  ];
  vitePlugins.push(createDevtools(viteEnv));
  vitePlugins.push(compression());
  vitePlugins.push(createAutoImport());
  vitePlugins.push(createComponents());

  return vitePlugins;
}
